﻿using System;

namespace EpiNEXT.Services.Validation.Functions
{
    public sealed class Seconds : DateDiffBase
    {
        public Seconds()
            : base()
        {

        }

        public override object Execute(Record record)
        {
            object result = base.Execute(record);

            if (result == null)
            {
                return result;
            }
            else if (result is TimeSpan)
            {
                TimeSpan span = (TimeSpan)result;

                if (span.Days < 0)
                {
                    return null;
                }

                TimeSpan ts = EndDate.Value.Subtract(StartDate.Value);
                return (int)ts.TotalSeconds;
            }
            else
            {
                return null;
            }
        }
    }
}
